package db.exchange.message;

import java.util.Queue;

public class Order {
	private String clientId;
	private String orderId;
	private String symbol;
	private Operation operation;
	private double price;
	private int qty;
	private int leavesQty;
	private int cumQty;
	private OrderStatus status;

	public String getClientId() {
		return clientId;
	}

	public String getOrderId() {
		return orderId;
	}

	public double getPrice() {
		return price;
	}

	public int getLeavesQty() {
		return leavesQty;
	}

	public int getQty() {
		return qty;
	}

	public Operation getOperation() {
		return operation;
	}

	public void fill(int fillQty, double fillPx, Queue<Message> outQueue) {
		Message message;
		leavesQty -= fillQty;
		cumQty += fillQty;

		if (leavesQty > 0)
			message = new Message(this, MessageType.PARTFILL);
		else if (leavesQty == 0)
			message = new Message(this, MessageType.FILL);
		else {
			message = new Message(this, MessageType.FILL);
			System.out.println("ERROR : OVERFILL " + this);
		}
		message.setLastPrice(fillPx);
		message.setLastQty(fillQty);
		outQueue.add(message);
	}

//	public void sendAck(Queue<Message> outQueue) {
//		Message message = new Message(this);
//		message.setType(MessageType.ACK);
//		outQueue.add(message);
//		// System.out.println("send ack"+this);
//	}

	public Order(String clientId, String orderId, String symbol, Operation operation,
			double price, int qty) {
		this.orderId = orderId;
		this.clientId = clientId;
		this.symbol = symbol;
		this.operation = operation;
		this.price = price;
		this.qty = qty;
		this.cumQty = 0;
		this.leavesQty = qty;
	}

	@Override
	public String toString() {
		return orderId + ":" + operation + ":"	+ price + ":" + leavesQty  +":" + status ;
	}

	public int getCumQty() {
		return cumQty;
	}

	public String getSymbol() {
		return symbol;
	}

	public void setLeavesQty(int leavesQty) {
		this.leavesQty = leavesQty;
	}

	public void setCumQty(int cumQty) {
		this.cumQty = cumQty;
	}

	public void setStatus(OrderStatus status) {
		this.status = status;
	}

	
	
}
